﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;


class CameraOperationTutorialNode : TutorialEventNode
{
    [JsonAttribute("lctype", "摄像机定位方式")]
    public ElementType cameraLocateType = ElementType.areaIndex;
    
    [JsonAttribute("bdID", "建筑配置表ID", "lctype", "", "buildingID")]
    public int buildingID = -1;

    [JsonAttribute("areaidx", "格子下标", "lctype", "", "areaIndex")]
    public Vector2Int areaIndex = new Vector2Int(-1, -1);

    [JsonAttribute("disim", "平滑移动距离上限,超过之后就是瞬间移动")]
    public float disForMoveImmediately = 100;

    [JsonAttribute("camerx", "摄像机X旋转")]
    public float cameraXRotation = 70;

    [JsonAttribute("caht", "摄像机位置")]
    public Vector3 cameraPostion = new Vector3(0,234.923f,-85.505f);

    public GameObject cacheObj;

    public static PinchTwistMove cameraController
    {
        get
        {
            if (_cameraController == null)
            {
                _cameraController = Camera.main.transform.parent.Find("Pinch & Twist & Move").GetComponent<PinchTwistMove>();
            }
            return _cameraController;
        }
    }
    public static PinchTwistMove _cameraController;

    protected override void Cancel()
    {
        GameObject.Destroy(cacheObj);
    }

    protected override void Init()
    {
        InitStart();
    }

    protected void InitStart()
    {
        cacheObj = new GameObject("Tutorial_Camera_Target");
        switch (cameraLocateType)
        {
            case ElementType.areaIndex:
                cacheObj.transform.position = CustomBuildUtils.GetWorldPosByValume(UserManager.Instance.AreaId, areaIndex.y, areaIndex.x, 0);
                break;
            case ElementType.buildingID:
                var data = Building.BuildingManager.Instance.GetSelfBuildingbyConfigId(buildingID);
                if (data == null)
                {
                    Debug.LogError("Building id not find is Game, Id is :" + buildingID);
                    return;
                }
                var buildingObj = CustomBuildManager.Instance.GetGobehaivour(data.buildingID);
                cacheObj.transform.position = buildingObj.position;
                break;
            default:
                Debug.LogError("locate error");
                break;
        }

        Vector3 objPos = cacheObj.transform.position;
        
        cameraController.SetTarget(objPos, true);
        Camera.main.transform.localPosition = cameraPostion;
        Camera.main.transform.localEulerAngles = new Vector3(cameraXRotation, 0, 0);
        this.Shoot();
    }
}

